USE [GESTION2]
GO

/****** Object:  StoredProcedure [dbo].[WASP_D0008_CREA_TABLA]    Script Date: 11/22/2011 17:13:55 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[WASP_D0008_CREA_TABLA]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[WASP_D0008_CREA_TABLA]
GO

USE [GESTION2]
GO

/****** Object:  StoredProcedure [dbo].[WASP_D0008_CREA_TABLA]    Script Date: 11/22/2011 17:13:55 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<JJ>
-- Create date: <01/08/2011>
-- Description:	<CREA TABLAS>
-- =============================================
CREATE PROCEDURE [dbo].[WASP_D0008_CREA_TABLA] 

AS
BEGIN
select	
	a.rut,
	a.dv,
	a.nombre,
	a.suc as AGCOLOC,
	rtrim(ltrim(a.nro_credito)) as nro_credito,
	cast(convert( varchar, a.inicio_cobertura,112)as decimal(8,0)) as inicio_cobertura,
	cast(convert( varchar, a.fin_cobertura,112)as decimal(8,0)) as FIN_COBERTURA,
	b.cuotas as NROCUOTAS,
	a.tlfonopen,
	a.dirtrabaja + ' ' + c.z07310dsc as DIRTRABAJA
into  dbo.seguro_proteccion_temp	
from 
spt_temp a left join as_cuotas_spt_temp b on
a.suc = b.aosuc and 
a.rut = b.aocta and 
a.nro_credito = b.aooper 
Left join z07310 c (nolock) on
a.comuna = c.z07310com
	
--	spt_temp a,
--	as_cuotas_spt_temp b, 
--	z07310 c (nolock)
	
--where
--a.suc *= b.aosuc and 
--a.rut *= b.aocta and 
--a.nro_credito *= b.aooper and 
--a.comuna *= c.z07310com

END

GO

